package com.ranjiaqi.commons;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @ClassName TestCommonsIOutils
 * @Description TODO
 * @Author hp
 * @Date 2021/7/2 19:56
 * @Version 1.0
 **/
public class TestCommonsIOutils {
    public static void main(String[] args) throws IOException {
//        Copy();
//        fileUtileWrite();
//        FileUtilesRead();
        FileUtilesCopyDiectory();
    }

    public static void Copy() throws IOException {
        FileWriter writer = new FileWriter("F:/java/2.txt");
        FileReader fileReader = new FileReader("F:/java/1.txt");
        IOUtils.copy(fileReader,writer);
        IOUtils.closeQuietly(writer);
        IOUtils.closeQuietly(fileReader);
    }

    public static void fileUtileWrite() throws IOException {
        FileUtils.writeStringToFile(new File("F:/java/1.txt"),"嘻嘻嘻嘻嘻",true);
    }

    public static void FileUtilesRead() throws IOException {
        String s = FileUtils.readFileToString(new File("F:/java/1.txt"));
        System.out.println("s = " + s);
    }
    public static void FileUtilesCopyDiectory() throws IOException {
        FileUtils.copyDirectory(new File("F:/java"),new File("E:\\"));
    }
}
